<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.hwhp.util.DTreeNode"%>

<%@ page import="net.sf.json.JSONArray" %>
<%@ page import="com.hwhp.entity.Deptment" %>
<%@ page import="com.hwhp.service.console.DepartService,com.hwhp.service.console.impl.DepartServiceImpl" %>
<%@ page import="java.util.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	DepartService departService = new DepartServiceImpl();
%>
<%
	String topOrgId = request.getParameter("deptid");
	List<DTreeNode> nodeList = new ArrayList<DTreeNode>();
	List<Deptment> subOrgList=departService.getChildDepts(topOrgId);
	String action="";
	 for(Deptment suborg:subOrgList){
	    String src=basePath+"html/login/departSelSubTree.jsp";
	    DTreeNode node = new DTreeNode();
		String suborgId=suborg.getDeptId();
		//System.out.print("\n**********suborgId="+suborgId+"********\n");
		List suborgList=departService.getChildDepts(suborgId);
		node = new DTreeNode();
		node.setText(suborg.getDeptName());
		node.setCheckboxType(0);
		node.setIcon(basePath+"js/tree/xtree/xloadtree/images/xtree_foldericon1.gif");
		node.setOpenIcon(basePath+"js/tree/xtree/xloadtree/images/xtree_openfoldericon1.gif");
		node.setTarget("");		
		node.setValue(suborgId);
		if(suborgList!=null&&suborgList.size()>0 ){
		   src=src+"?deptid="+suborgId;
		  node.setSrc(src);
		  action="javascript:doSelect('"+suborgId+"','"+suborg.getDeptName()+"')";
		}else{
		  node.setIcon(basePath+"js/tree/xtree/xloadtree/images/ico2.gif");
		     node.setSrc("");
		     action="javascript:doSelect('"+suborgId+"','"+suborg.getDeptName()+"')";
		}	
		node.setAction(action);
		nodeList.add(node); 	
	}
	
	JSONArray jsonArray = JSONArray.fromCollection(nodeList);
	
    out.print(jsonArray.toString());
%>